﻿using ShareCode.Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ShareCode.Dto
{
    public class PagingDto : SearchDto
    {
        int _pageSize = 20;
        int _current = 1;
        int _total;
        long _lastId = long.MaxValue;

        public int PageSize
        {
            set
            {
                if (value > 0) _pageSize = value;
            }
            get => _pageSize;
        }
        public int CurrentPage
        {
            set
            {
                if (value > 0) _current = value;
            }
            get => _current;
        }
        public int TotalRows
        {
            set
            {
                if (value > -1) _total = value;
            }
            get => _total;
        }
        public long LastId
        {
            set
            {
                if (value > -1) _lastId = value;
            }
            get => _lastId;
        }
        public bool? IsDesc { get;  set; }

        public void Init(PagingDto paging)
        {
            this.PageSize = paging.PageSize;
            this.CurrentPage = paging.CurrentPage;
            this.TotalRows = paging.TotalRows;
            this.LastId = paging.LastId;
            if (OrderField.Count() < 1)
            {
                IsDesc = true;
            }
            else if (OrderField.TryGetValue(nameof(BaseBaseEntity.Id), out bool order))
            {
                IsDesc = order;
            }

        }
    }
}
